package com.slkj.shilixiaoyuanapp.ui.main.message;

import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.LazyFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;

/**
 * Created  on 2018-07-15
 *
 * @author 唐开阔
 * @describe 首页消息fragment
 */
public class MessageMainFragment extends LazyFragment {
    @BindArray(R.array.main_message_tab)
    String[] titles;
    @BindView(R.id.tab_layout)
    SlidingTabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    FragmentPagerAdapter fragmentPagerAdapter;
    private List<Fragment> fragments = new ArrayList<>();

    @Override
    protected int getResId() {
        return R.layout.fragment_message;
    }

    @Override
    protected void onRealLoaded() {
        fragments.add(new MessageNoticeFragment());
        fragments.add(new MessageContactsFragment());
        fragmentPagerAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        };
        viewpager.setAdapter(fragmentPagerAdapter);
        tablayout.setViewPager(viewpager);

    }
}
